<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        list_num = [1332, 45, 43243, 4346, 34234, 656, 323, 99999]

        //找到最大值  

        function get_newarr(arr) {
            var max = arr[0];
            var min = arr[0];
            var maxIndex = 0;
            var minIndex = 0
            for (var i = 1; i < arr.length; i++) {
                if (arr[i] > max) {
                    max = arr[i];
                    maxIndex = i;
                }

                if (arr[i] < min) {
                    min = arr[i];
                    minIndex = i;
                }
            }

            var temp1 = list_num[maxIndex];
            list_num[maxIndex] = arr[0];
            arr[0] = temp1;

            var temp2 = list_num[minIndex];
            list_num[minIndex] = arr[arr.length - 1];
            arr[arr.length - 1] = temp2;


            return arr;
        }

        console.log(get_newarr(list_num))
    </script>
</body>

</html>